﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Deepprocessings;
using Traceability.APP.Application.Command.Slaughters;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Deepprocessings
{
    public class UpdateMachiningEnterpriseCommandHandLer : IRequestHandler<UpdateMachiningEnterpriseCommand, APIResult<int>>
    {


        private readonly IBaseRepostiy<MachiningEnterprise> _machiningEnterprise;
        private readonly IMapper mapper;

        public UpdateMachiningEnterpriseCommandHandLer(IBaseRepostiy<MachiningEnterprise> machiningEnterprise, IMapper mapper)
        {
            _machiningEnterprise = machiningEnterprise;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(UpdateMachiningEnterpriseCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<MachiningEnterprise>(request);
            list.UpdateUserTime = DateTime.Now;
            var res = await _machiningEnterprise.Update(list);

            result.Code = ResultCode.Ok;
            result.Message = "企业信息修改成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
